﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;

namespace UserForms
{
    class ADOopertion
    {
        private static readonly string connstr = "server=.;database=ShoolMessage;user=sa;pwd=123456";

        private static readonly SqlConnection myconn = new SqlConnection(connstr);


        /// <summary>
        /// 查找数据
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        public static DataTable Select(string sql)
        {
            myconn.Open();

            SqlDataAdapter dataAdapter = new SqlDataAdapter(sql, myconn);

            DataTable myTable = new DataTable();

            dataAdapter.Fill(myTable);

            myconn.Close();

            return myTable;

        }



        /// <summary>
        /// 添加数据、删除数据、更改数据
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        /// 
        public static int DeleteUpdateInsert(string sql)
        {
            myconn.Open();

            SqlCommand mycomm = new SqlCommand(sql, myconn);

            var i = mycomm.ExecuteNonQuery();

            myconn.Close();

            return i;
        }

    }
}
